package org.abettor.leaf4e.tester;

import org.abettor.leaf4e.Activator;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.jdt.core.IJavaProject;

/**
 * 检测是否属于LEAF项目
 * @author shawn
 *
 */
public class ProjectTester extends PropertyTester
{
	@Override
	public boolean test(Object receiver, String property, Object[] args, Object expectedValue)
	{
		if(receiver == null || expectedValue == null)
		{
			return false;
		}

		if(! (expectedValue instanceof Boolean))
		{
			return false;
		}
		boolean expected = (Boolean) expectedValue;

		if(! (receiver instanceof IJavaProject))
		{
			return false;
		}
		IJavaProject jp = (IJavaProject) receiver;
		IProject project = jp.getProject();
		IFile sign = project.getFile(Activator.PLUGIN_CONF);
		boolean flag = false;
		if(sign.exists())
		{
			flag = true;
		}

		if(expected)
		{
			return flag;
		}
		else
		{
			return ! flag;
		}
	}
}
